<?php

declare(strict_types=1);

namespace App\Controller\delivery;
use App\Controller\BaseController;
use App\Model\Applet;
use App\Model\AppletCompany;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\Di\Annotation\Inject;
use App\Model\Company;
use App\Service\delivery\CompanyService;
use App\Common\Response\SystemCode;

#[AutoController]
class CompanyController  extends BaseController
{

    #[Inject]
    private CompanyService $companyService;
    /**
     * 公司列表
     */

    public function getApplet()
    {
        $userInfo = $this->companyService->getUserAppletInfo(2);
        $company_id = $userInfo['company_id'];
        $companyInfo = Company::query()->where(['id' => $company_id])->first();
        if (empty($companyInfo)) {
            return $this->response(SystemCode::SYSTEM_ERROR, '公司不存在');
        }
        $appletIds = AppletCompany::query()->where(['company_id' => $companyInfo->id])->pluck('applet_id');
        $selectData = Applet::query()->whereIn('id',$appletIds)->select('id as value','name as label')->get();
        return $this->response(SystemCode::SYSTEM_SUCCESS, '查询成功',$selectData);

    }
}